Belgelerim/ceng_491/implementation/doxygen/TraffEdu_Developers_Manual_Reference_ToSource/TrafficLight.cpp

Go to the documentation of this file.
00001 /*
00002 * TrafficLight class inherits from TraffEduObject class
00003 */
00004 
00005 #pragma once
00006 
00007 #include "../stdafx.h"
00008 #include "../MainFrm.h"
00009 #include "TrafficLight.h"
00010 
00011 #include <osg/Node>
00012 #include <osg/Matrix>
00013 #include <osg/Geode>
00014 #include <osg/ShapeDrawable>
00015 #include <osg/Material>
00016 #include <osg/Texture2D>
00017 #include <osg/MatrixTransform>
00018 #include <osg/PositionAttitudeTransform>
00019 #include <osg/BlendFunc>
00020 #include <osg/ClearNode>
00021 #include <osg/Projection>
00022 #include "../0SGWindows/OSGWindows.h"//18nisan_ebru
00023 
00024 /*
00025 * Constructor for TrafficSign
00026 * Default is NORMAL_ISIK, YESIL light.
00027 *
00028 **/
00029 
00030 TrafficLight::TrafficLight(OSGWindows* osgwind__):TraffEduObject()
00031 {
00032         for(int i=0;i<101;i++)
00033                 colorArray[i]=0;
00034         lightType = NORMAL_ISIK ;
00035         color = YESIL;
00036         arrowColor = YESIL;
00037         this->setObjectType(LIGHT); 
00038         objectGroup->setName("TrafficLight");
00039         setObjectId();
00040         osgwind_ = osgwind__;   
00041         seqNode = new osg::Sequence;
00042 }
00043 
00044 TrafficLight::TrafficLight(OSGWindows* osgwind,TrafficLightTypes newType,TrafficLightColor newColor, TrafficLightColor newArrowColor)
00045 {
00046         osgwind_ = osgwind;
00047         fillColorArray(newColor);
00048         lightType=newType;
00049         color=newColor;
00050         arrowColor=newArrowColor;
00051         this->setObjectType(LIGHT); 
00052         objectGroup->setName("TrafficLight");
00053         setObjectId(); 
00054         seqNode = new osg::Sequence;
00055 }
00056 
00057 TrafficLight::~TrafficLight()
00058 {
00059 }
00060 
00061 /*
00062 * Draw functin for TrafficSign is responsible 
00063 * from adding itself to the transformation matrix node of its
00064 * base class TraffEduObject, as a child of transformation matrix node.
00065 * After adding itself as a child of transformationmatrix, it calls the addTree()
00066 * function to be added fully to the scene node, root.
00067 * It uses the TrafficModel classes static function trafficLight to get the light model node.
00068 ***/
00069 
00070 void TrafficLight::draw(osg::ref_ptr<osg::Group> root,int animationFlag)
00071 {
00072         if( animationFlag  != -1)
00073         {
00074                 if(objectGroup->getNumChildren())
00075                 {
00076                         objectGroup->removeChild(0,1);
00077                 }
00078                 objectGroup->addChild(seqNode.get());
00079                 addTree(root) ;
00080         }else {
00081         if(objectGroup->getNumChildren())
00082         {
00083                 objectGroup->removeChild(0,1);
00084 
00085         }
00086 
00087         else
00088                 addTree(root) ;
00089 
00090         objectGroup->addChild((TrafficModel::trafficLight(getFrameColor(osgwind_->getCurrentFrameId()))).get());
00091         
00092         }
00093         viewMode=1;
00094 
00095         isBeforeCreated = 1;
00096 }
00097 
00098 void TrafficLight::changeColor(int frameId)
00099 {
00100         colorArray[frameId]= ((colorArray[frameId] + 1)%3);
00101         TrafficLightColor newColor=getFrameColor(frameId);
00102         objectGroup->removeChild(0,1);
00103         objectGroup->addChild((TrafficModel::trafficLight(newColor)).get());
00104 }
00105 
00106 void TrafficLight::changeColorAnim(int frameId)
00107 {
00108         TrafficLightColor newColor=getFrameColor(frameId);
00109         objectGroup->removeChild(0,1);
00110         objectGroup->addChild((TrafficModel::trafficLight(newColor)).get());
00111 }
00112 
00113 
00114 void TrafficLight::fillColorArray(TrafficLightColor newColor)
00115 {
00116         if(newColor == YESIL)
00117         {
00118                 for(int i=0;i<101;i++)
00119                 colorArray[i]=0;
00120         }       
00121         else if(newColor == SARI)
00122         {
00123                 for(int i=0;i<101;i++)
00124                 colorArray[i]=1;
00125         }
00126         else
00127         {
00128         for(int i=0;i<101;i++)
00129                 colorArray[i]=2;
00130         }
00131 }
00132 
00133 TrafficLightColor TrafficLight::getFrameColor(int frameId)
00134 {
00135         if(colorArray[frameId] == 0)
00136                 return YESIL;
00137         else if(colorArray[frameId] == 1)
00138                 return SARI;
00139         else if(colorArray[frameId] == 2)
00140                 return KIRMIZI;
00141 }
00142 
00143 void TrafficLight::setFrameColor(int frameId,int color)
00144 {
00145         if(color == 0)
00146                 colorArray[frameId]=2;
00147         else if(color == 1)
00148                 colorArray[frameId]=1;
00149         else if(color == 2)
00150                 colorArray[frameId]=0;
00151 }
00152 void TrafficLight::setNewFramesLightColor(int oldFrameId,int newFrameId)
00153 {
00154         colorArray[newFrameId] = colorArray[oldFrameId];
00155 }
00156 
00157 void TrafficLight::setColor(TrafficLightColor newColor){
00158         color = newColor;
00159 }
00160 

Generated on Sun May 28 18:54:09 2006 for TraffEdu by  doxygen 1.4.6-NO